package se.chalmers.spexet.booking.common;

public class Setting {
	private Object value;
	private int type;
	/*
	 * 0 = undef
	 * 1 = bool
	 * 2 = int
	 * 3 = String 
	 */
	
	public Setting(String s) {
		Object o;
		if(s.equalsIgnoreCase("true") || s.equals("1"))
			o = new Boolean(true);
		else if(s.equalsIgnoreCase("false") || s.equals("0"))
			o = new Boolean(false);
		else
			o = s;
		try {
			int i = Integer.parseInt(s);
			o = new Integer(i);
		} catch (NumberFormatException e) {
			;
		}
		
		type = 0;
		if(o.getClass().getCanonicalName().equals("Boolean"))
			type = 1;
		else if(o.getClass().getCanonicalName().equals("Integer"))
			type = 2;
		else if(o.getClass().getCanonicalName().equals("String"))
			type = 3;
		else 
			throw new ClassCastException("Uncompatible!");
		value = o;
	}
	
	public Boolean getBool() {
		if(type == 1)
			return ((Boolean) value);
		return null;
	}
	
	public Integer getInt() {
		if(type == 2)
			return (Integer) value;
		return null;
	}
	
	public String getString() {
		if(type == 3)
			return (String) value;
		return null;
	}
}
